<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xsl:output method="xml" version="1.0" encoding="utf-8" indent="no"/>

	<xsl:template match="*|@*|processing-instruction()">
		<xsl:copy>
			<xsl:apply-templates select="@*"/>
			<xsl:apply-templates/>
		</xsl:copy>
	</xsl:template>

	<xsl:template match="refsect1[title='Facets:']">
		<xsl:copy>
			<title>Data parameters (facets):</title>
			<para>
				<xsl:call-template name="facets"/>
			</para>
		</xsl:copy>
	</xsl:template>

	<xsl:template name="facets">
		<xsl:param name="facets" select="concat(normalize-space(translate(para, ',', ' ')), ' ')"/>
		<literal>
			<xsl:value-of select="substring-after(substring-before($facets, ' '), 'xsd:')"/>
		</literal>
		<xsl:variable name="next" select="substring-after($facets, ' ')"/>
		<xsl:choose>
			<xsl:when test="$next='xsd:whiteSpace ' or $next=''">
				<xsl:text>.</xsl:text>
			</xsl:when>
			<xsl:otherwise>
				<xsl:text>, </xsl:text>
				<xsl:call-template name="facets">
					<xsl:with-param name="facets" select="$next"/>
				</xsl:call-template>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template match="@id[starts-with(., 'IXT-16')]">
		<xsl:attribute name="id">
			<xsl:text>IXT-17</xsl:text>
			<xsl:value-of select="substring-after(., 'IXT-16')"/>
		</xsl:attribute>
	</xsl:template>
	
	<xsl:template match="@id[starts-with(., 'ch16')]">
		<xsl:attribute name="id">
			<xsl:text>ch17</xsl:text>
			<xsl:value-of select="substring-after(., 'ch16')"/>
		</xsl:attribute>
	</xsl:template>
	
</xsl:stylesheet>
